package logic

import (
	"context"
	"mei-tuan-admin/userrpc/userrpc"

	"mei-tuan-admin/api/internal/svc"
	"mei-tuan-admin/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type LoginApiLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewLoginApiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginApiLogic {
	return &LoginApiLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *LoginApiLogic) LoginApi(req *types.LoginRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	login, err := l.svcCtx.UserRpc.Login(l.ctx, &userrpc.LoginRequest{
		Mobile:      req.Mobile,
		Password:    req.Password,
		CaptchaCode: req.CaptchaCode,
		SendSmsCode: req.SendSmsCode,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    0,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "登录成功",
		Code:    200,
		Data:    login,
	}, nil
}
